package com.blog.service;

import com.blog.domain.Blog;
import com.blog.domain.Type;
import com.blog.domain.User;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./src/blog-security-context.xml",
		"file:./src/blog-service-context.xml",
		"file:./src/blog-dao-context.xml",
		"file:./src/blog-web-context.xml" })
@Transactional
public class UserServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected UserService service;

	/**
	 * Instantiates a new UserServiceTest.
	 *
	 */
	public UserServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Return all User entity
	 * 
	 */
	@Test
	public void findAllUsers() {
		// TODO: JUnit - Populate test inputs for operation: findAllUsers 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<User> response = null;
		response = service.findAllUsers(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllUsers
	}

	/**
	 * Operation Unit Test
	 * Save an existing User entity
	 * 
	 */
	@Test
	public void saveUser() {
		// TODO: JUnit - Populate test inputs for operation: saveUser 
		User user = new com.blog.domain.User();
		service.saveUser(user);
	}

	/**
	 * Operation Unit Test
	 * Return a count of all User entity
	 * 
	 */
	@Test
	public void countUsers() {
		Integer response = null;
		response = service.countUsers();
		// TODO: JUnit - Add assertions to test outputs of operation: countUsers
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findUserByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findUserByPrimaryKey 
		Integer id = 0;
		User response = null;
		response = service.findUserByPrimaryKey(id);
		// TODO: JUnit - Add assertions to test outputs of operation: findUserByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Blog entity
	 * 
	 */
	@Test
	public void deleteUserBlogs() {
		// TODO: JUnit - Populate test inputs for operation: deleteUserBlogs 
		Integer user_id = 0;
		Integer related_blogs_id = 0;
		User response = null;
		response = service.deleteUserBlogs(user_id, related_blogs_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteUserBlogs
	}

	/**
	 * Operation Unit Test
	 * Delete an existing User entity
	 * 
	 */
	@Test
	public void deleteUser() {
		// TODO: JUnit - Populate test inputs for operation: deleteUser 
		User user_1 = new com.blog.domain.User();
		service.deleteUser(user_1);
	}

	/**
	 * Operation Unit Test
	 * Save an existing Blog entity
	 * 
	 */
	@Test
	public void saveUserBlogs() {
		// TODO: JUnit - Populate test inputs for operation: saveUserBlogs 
		Integer id_1 = 0;
		Blog related_blogs = new com.blog.domain.Blog();
		User response = null;
		response = service.saveUserBlogs(id_1, related_blogs);
		// TODO: JUnit - Add assertions to test outputs of operation: saveUserBlogs
	}

	/**
	 * Operation Unit Test
	 * Load an existing User entity
	 * 
	 */
	@Test
	public void loadUsers() {
		Set<User> response = null;
		response = service.loadUsers();
		// TODO: JUnit - Add assertions to test outputs of operation: loadUsers
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Type entity
	 * 
	 */
	@Test
	public void deleteUserTypes() {
		// TODO: JUnit - Populate test inputs for operation: deleteUserTypes 
		Integer user_id_1 = 0;
		Integer related_types_id = 0;
		User response = null;
		response = service.deleteUserTypes(user_id_1, related_types_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteUserTypes
	}

	/**
	 * Operation Unit Test
	 * Save an existing Type entity
	 * 
	 */
	@Test
	public void saveUserTypes() {
		// TODO: JUnit - Populate test inputs for operation: saveUserTypes 
		Integer id_2 = 0;
		Type related_types = new com.blog.domain.Type();
		User response = null;
		response = service.saveUserTypes(id_2, related_types);
		// TODO: JUnit - Add assertions to test outputs of operation: saveUserTypes
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
